#ifndef EDITOR_H
#define EDITOR_H

#include <QTextEdit>
#include <QFile>
#include <QByteArray>
#include "UserHighlighter/userhighlighter.h"
#include "Change/change.h"

class DocumentManager;

/**
  * Simple abstract base graphical WeaveEdit editor, can be a text or formatted editor.
  */
class Editor : public QTextEdit
{
	Q_OBJECT

	public:
		const static char *DEFAULT_NAME;

		enum Type {TEXT, FORMATTED};

		Editor(DocumentManager *newManager);
		virtual ~Editor();

		virtual Type getType() const = 0;
		QString getFileName() const { return file.fileName(); }
		QString getTabName() const {return tabName;}
		int getDocId() {return docId;}
		UserHighlighter *getUserHighlighter() {return highlighter;}
		QList<Change> getChangeList() {return changeList;}

		void setFileName(const QString newFileName) { file.setFileName(newFileName); }
		void setDocId(int newId) {docId = newId;}
		void setTabName(QString newName) {tabName = newName;}

		virtual void saveFile() = 0;
		virtual void saveFile(QString) = 0;                 //Save out actual file information
		virtual void saveFile(QByteArray&) = 0;		    //Create a QByteArray of the data to be saved
		virtual QString saveSession(QString filename);      //Initiate the saving process and grab other variables.
		virtual void saveUserStats(QString);                //Save information for building user statistics, implemented as same for both types
		virtual void saveUserStats(QByteArray&);	    //Get a QByteArray of information to be saved

		virtual void loadFile(QString) = 0;                 //Load up 'text' bit of the document
		virtual void loadFile(QByteArray) = 0;
		virtual void loadSession(QString filename, QStringList metadata);
		virtual void setMeta(QStringList);		    //Set the metadata of the file
		virtual QString getMeta();			    //Get information relating to documents without saving to file
		virtual void loadUserStats(QString);		    //Load in the userstatistics from a file given the filename or
		virtual void loadUserStats(QByteArray);		    //given a QByteArray containing this information directly

		virtual void receiveChange(QByteArray change) = 0;

	public slots:
		virtual void textChanged(int position, int charsRemoved, int charsAdded) = 0;
		void hideOrRestoreDocument(bool checked);
		void indent();
		void unindent();
		void selectAll();
		void selectNone();
		void copy();
		void cut();
		void paste();
		void deleteSelection();
		void undo();
		void redo();
		void copyIsAvaliable(bool available);

	protected:
		bool modsSaved;
		QFile file;
		int docId;
		DocumentManager *documentManager;
		UserHighlighter *highlighter;
		QList<Change> changeList;
		int revisionNum;
		QString tabName;
};

#endif // EDITOR_H
